}
this.section = new PopupMenu.PopupMenuSection();
- this._createSection();
+ this._deferredWorkId = Main.initializeDeferredWork(this.section.actor, Lang.bind(this, this._createSection));
},
destroy: function() {
this._activeConnection = activeConnection;
this._clearSection();
- this._createSection();
+ this._queueCreateSection();
},
checkConnection: function(connection) {
- let exists = this._findConnection(connection._uuid) != -1;
+ let pos = this._findConnection(connection._uuid);
+ let exists = pos != -1;
let valid = this.connectionValid(connection);
+
if (exists && !valid)
this.removeConnection(connection);
else if (!exists && valid)
this.addConnection(connection);
+ else if (exists && valid) {
+ // propagate changes and update the UI
+
+ if (this._connections[pos].timestamp != connection._timestamp) {
+ this._connections[pos].timestamp = connection._timestamp;
+ this._connections.sort(this._connectionSortFunction);
+
+ this._clearSection();
+ this._queueCreateSection();
+ }
+ }
},
addConnection: function(connection) {
this._connections.sort(this._connectionSortFunction);
this._clearSection();
- this._createSection();
+ this._queueCreateSection();
},
removeConnection: function(connection) {
// (or in the case of NMDeviceWired, we want to hide
// the only explicit connection)
this._clearSection();
- this._createSection();
+ this._queueCreateSection();
}
},
return -1;
},
+ _queueCreateSection: function() {
+ this._clearSection();
+ Main.queueDeferredWork(this._deferredWorkId);
+ },
+
_clearSection: function() {
// Clear everything
this.section.removeAll();
this._updateStatusItem();
this._clearSection();
- this._createSection();
+ this._queueCreateSection();
this.emit('state-changed');
},
this._autoConnectionName = this._makeConnectionName(this.device);
this._clearSection();
- this._createSection();
+ this._queueCreateSection();
+ this._updateStatusItem();
+ },
+
+ _getDescription: function() {
+ return this.device.name || _("Bluetooth");
}
});
}
if (needsupdate) {
- if (apObj.item)
- apObj.item.destroy();
-
- if (pos != -1)
- this._networks.splice(pos, 1);
-
- if (this._networks.length == 0) {
- // only network in the list
- this._networks.push(apObj);
- this._clearSection();
- this._createSection();
- return;
- }
-
- // skip networks that should appear earlier
- let menuPos = 0;
- for (pos = 0;
- pos < this._networks.length &&
- this._networkSortFunction(this._networks[pos], apObj) < 0; ++pos) {
- if (this._networks[pos] != this._activeNetwork)
- menuPos++;
- }
-
- // (re-)add the network
- this._networks.splice(pos, 0, apObj);
-
- if (this._shouldShowConnectionList()) {
- menuPos += (this._activeConnectionItem ? 1 : 0);
- this._createNetworkItem(apObj, menuPos);
- }
+ this._clearSection();
+ this._queueCreateSection();
}
},
let obj = this._connections[pos];
this._connections.splice(pos, 1);
- let anyauto = false, forceupdate = false;
+ let forceupdate = false;
for (let i = 0; i < this._networks.length; i++) {
let apObj = this._networks[i];
let connections = apObj.connections;
if (connections[k]._uuid == connection._uuid) {
// remove the connection from the access point group
connections.splice(k);
- anyauto = connections.length == 0;
+ forceupdate = forceupdate || connections.length == 0;
- if (anyauto) {
- // this potentially changes the sorting order
- forceupdate = true;
+ if (forceupdate)
break;
- }
+
if (apObj.item) {
if (apObj.item instanceof PopupMenu.PopupSubMenuMenuItem) {
- let items = apObj.item.menu.getMenuItems();
+ let items = apObj.item.menu._getMenuItems();
if (items.length == 2) {
// we need to update the connection list to convert this to a normal item
forceupdate = true;
}
}
- if (forceupdate || anyauto) {
+ if (forceupdate) {
this._networks.sort(this._networkSortFunction);
this._clearSection();
- this._createSection();
+ this._queueCreateSection();
}
},
if (forceupdate) {
this._networks.sort(this._networkSortFunction);
this._clearSection();
- this._createSection();
+ this._queueCreateSection();
}
},
_createActiveConnectionItem: function() {
let icon, title;
- if (this._activeConnection._connection) {
+ if (this._activeConnection && this._activeConnection._connection) {
let connection = this._activeConnection._connection;
if (this._activeNetwork)
this._activeConnectionItem = new NMNetworkMenuItem(this._activeNetwork.accessPoints, undefined,
if (!this._shouldShowConnectionList())
return;
- if(this._activeConnection) {
+ if (this._activeNetwork) {
this._createActiveConnectionItem();
this.section.addMenuItem(this._activeConnectionItem);
}